package com.dream.house.dao.base;

import java.util.HashMap;
import java.util.Map;

import cn.com.servyou.base.dao.BaseDAO;
import cn.com.servyou.base.exception.DAOException;
import cn.com.servyou.utils.Page;

public abstract class HouseBaseDAO extends BaseDAO implements IDAO{
	/**
	 * 分页查询
	 * @param condition
	 * @param pageNo
	 * @param pageSize
	 * @return Page
	 * @throws DAOException
	 */
	public Page findByPage(Map<String, Object> condition, int pageNo,
			int pageSize) throws DAOException {
		condition.put("pageSize", Integer.valueOf(pageSize));
		condition.put("minRow", Integer.valueOf((pageNo<=0?0 : (pageNo- 1)) * pageSize));
		
		return findByPage("findByPage", "findByPageCount", condition, pageNo, pageSize);
	}
	
	/**
	 * 校验
	 * @param condition
	 * @return boolean
	 * @throws DAOException
	 */
	public boolean check(Map<String, String> condition) throws DAOException {
		
		return getEntitys("check", condition).size()>0;
	}

	/**
	 * 取最大ID号
	 * @return String
	 * @throws DAOException
	 */
	public String getMaxId() throws DAOException {
		if(getEntity("getMaxId")!=null){
			return String.valueOf(Integer.valueOf((String)getEntity("getMaxId"))+1);
		}
		return "10000001";
	}
	
	/**
	 * 审批
	 */
	public boolean grant(String id, String status,String checkUser,String s) throws DAOException {
		Map<String,String> map=new HashMap<String,String>();
		map.put("id", id);
		map.put("check_status", status);
		map.put("checkUser", checkUser);
		map.put("status", s);
		return updateEntity("grant", map);
	}
	
	public boolean removeByRoom(String room_id) throws DAOException{
		Map<String,String> map=new HashMap<String,String>();
		map.put("room_id", room_id);
		
		return removeEntity("removeByRoom", map);
	}	

}
